Page({
  data: {
    typeList: [
      { id: 1, name: '功能建议' },
      { id: 2, name: '环境卫生' },
      { id: 3, name: '设施维护' },
      { id: 4, name: '服务态度' },
      { id: 5, name: '其他' }
    ],
    feedbackType: 0,
    content: '',
    images: [],
    contact: ''
  },

  // 选择反馈类型
  onSelectType(e) {
    const { id } = e.currentTarget.dataset
    this.setData({ feedbackType: id })
  },

  // 输入反馈内容
  onInput(e) {
    this.setData({
      content: e.detail.value
    })
  },

  // 输入联系方式
  onContactInput(e) {
    this.setData({
      contact: e.detail.value
    })
  },

  // 选择图片
  chooseImage() {
    wx.chooseMedia({
      count: 4 - this.data.images.length,
      mediaType: ['image'],
      sourceType: ['album', 'camera'],
      success: (res) => {
        const newImages = res.tempFiles.map(file => file.tempFilePath)
        this.setData({
          images: [...this.data.images, ...newImages]
        })
      }
    })
  },

  // 删除图片
  deleteImage(e) {
    const { index } = e.currentTarget.dataset
    const images = this.data.images.slice()
    images.splice(index, 1)
    this.setData({ images })
  },

  // 提交反馈
  onSubmit() {
    const { feedbackType, content, images, contact } = this.data

    if (!feedbackType) {
      wx.showToast({
        title: '请选择反馈类型',
        icon: 'none'
      })
      return
    }

    if (!content.trim()) {
      wx.showToast({
        title: '请输入反馈内容',
        icon: 'none'
      })
      return
    }

    wx.showLoading({
      title: '提交中'
    })

    // TODO: 上传图片和提交反馈
    setTimeout(() => {
      wx.hideLoading()
      wx.showToast({
        title: '提交成功',
        icon: 'success',
        duration: 2000,
        success: () => {
          setTimeout(() => {
            wx.navigateBack()
          }, 2000)
        }
      })
    }, 1500)
  }
}) 